package com.service;

import com.mapper.SupplierMapper;
import com.pojo.Supplier;
import com.util.MyBatisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("supplierService")
public class SupplierServiceImpl implements SupplierService{
    @Resource
    private SupplierMapper supplierMapper;
    @Override
    public List<Supplier> select(String supCode, String supName, Integer pageBegin, Integer pageSize) {
        List<Supplier> supplierList = new ArrayList<>();
        try{
            supplierList = supplierMapper.select(supCode,supName,((pageBegin-1)*pageSize),pageSize);
        }catch (Exception e){
            e.printStackTrace();
        }
        return supplierList;
    }

    @Override
    public int count(String supCode, String supName) {
        int count = 0;
        try{
            count = supplierMapper.count(supCode, supName);
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }

    @Override
    public boolean add(Supplier supplier) {
        boolean result=false;
        if(supplierMapper.add(supplier)==1){
            result=true;
        }
        return result;
    }

    @Override
    public Supplier getSupplierById(String id) {
        return supplierMapper.getSupplierById(id);
    }

    @Override
    public boolean update(Supplier supplier) {
        boolean result=false;
        if(supplierMapper.update(supplier)==1){
            result=true;
        }
        return result;
    }

    @Override
    public List<Supplier> supplierList() {
        return supplierMapper.supplierList();
    }

    @Override
    public boolean del(String id) {
        boolean result=false;
        if(supplierMapper.del(id)==1){
            result=true;
        }
        return result;
    }
}